/*
* File: som_linear_solver.h
* @Brief: the linear solver in SOM.
* @Author: Mr.Charley(Chinese name: Chenglin Jia).
* @Version: 1.0
* @Date: 2024/7/22
*/

#ifndef SOM_LINEAR_SOLVER_H
#define SOM_LINEAR_SOLVER_H

#include "som_base.h"
#include "som_regularizer.h"

enum Som_Linear_Solver_ 
{ 
	PartialPivLU, 
	ColPivHouseholderQR, 
	VerbosePartialPivLU 
};

typedef enum Som_Linear_Solver_ Som_Linear_Solver;

/************************************************************************/
/*
 * @brief The partialPivLUSolver is a fast solver but it can't check for invertibility.
 * @param data: Data matrix with each row being a data sample.
 * @param labels: Labels for each data sample.
 * @param regularizer: regularizer A regularization.
 * @return the solver of linear system, (AtA+lamda*I)*x = At*b.
 */
 /************************************************************************/
SOM_EXPORT CvMat* partialPivLUSolver(const CvMat* data, const CvMat* labels, Som_Regularizer* som_regularizer);

/************************************************************************/
/*
 * @brief The verbosePartialPivLUSolver is a fast solver but it can't check for invertibility.
 * It supports parallel solving if compiled with OpenMP enabled.
 * @param data[in]: Data matrix with each row being a data sample.
 * @param labels[in]: Labels for each data sample.
 * @param som_regularizer[in&out]: regularizer A regularization.
 * @return the solver: of linear system, (AtA+lamda*I)*x = At*b.
 */
 /************************************************************************/
SOM_EXPORT CvMat* verbosePartialPivLUSolver(const CvMat* data, const CvMat* labels, Som_Regularizer* som_regularizer);

/************************************************************************/
/*
 * @brief The ColPivHouseholderQRSolver can check for invertibility, but it is much slower than a PartialPivLUSolver.
 * It prints out information about time, and it's helpful for debugging purposed.
 * @param data[in]: Data matrix with each row being a data sample.
 * @param labels[in]: Labels for each data sample.
 * @param som_regularizer[in&out]: regularizer A regularization.
 * @return the solver of linear system, (AtA+lamda*I)*x = At*b.
 */
 /************************************************************************/
SOM_EXPORT CvMat* colPivHouseholderQRSolve(const CvMat* data, const CvMat* labels, Som_Regularizer* som_regularizer);

#endif // !SOM_LINEAR_SOLVER_H
